package com.isp.aut.server.service;

import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.isp.aut.server.reference.ResourceReference;
import com.isp.common.model.user.GroupDTO;
import com.isp.common.model.vo.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
@RequiredArgsConstructor
public class GroupService {

    private final ResourceReference resourceReference;

    @Cached(name = "group4User::", key = "#username", cacheType = CacheType.BOTH, expire = 5)
    public List<GroupDTO> queryGroupsByUsername(String username) {
        Result<List<GroupDTO>> groups = resourceReference.groups(username);
        log.info("username:{},groups:{}", username, groups);
        return groups.getData();
    }
}
